package ps.client.plugin.eq2.log;

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class TraumaticSwipeTrigger extends Trigger {
	
	public static final String NAME = "TraumaticSwipe";
	public static final String REGEX = ".*Traumatic Swipe( critically)? hits.*";
	public static final int FLAGS = IGNORE_CHAT;
	
	String attacker = "*";
	String victim = "*";

	public TraumaticSwipeTrigger() {
		super(NAME, REGEX, FLAGS);
	}
	
	public String getAttacker() {
		return attacker;
	}
	
	public String getVictim() {
		return victim;
	}
	
	public void fireTriggerEvent(TriggerEvent e) {
		String content = e.getLogLine().getContent();
		
		if (content.startsWith("YOUR")) {
			attacker = e.getLogLine().getAvatarName();
		} else {
			int i1 = e.getLogLine().getContent().indexOf('\'');
			attacker = i1 > 0 ? e.getLogLine().getContent().substring(0, i1) : "*";
		}
		
		int i1 = content.indexOf(" hits ");
		if (i1 > 0) {
			int i2 = content.indexOf(" for ");
			victim = i2 > i1 ? content.substring(i1 + 6, i2) : "*";
		}
		
		super.fireTriggerEvent(e);
	}
	
	public static void main(String[] args) {
		TraumaticSwipeTrigger trigger = new TraumaticSwipeTrigger();
		String line = "(1244914376)[Sat Jun 13 19:32:56 2009] Cexi's Traumatic Swipe critically hits Avatar of Growth for 2592 piercing damage.";
		Matcher matcher = Pattern.compile(REGEX).matcher(line);
		if (matcher.matches()) {
			trigger.fireTriggerEvent(new TriggerEvent(trigger, new LogLine(null, line), matcher));
			System.out.println("attacker: \"" + trigger.getAttacker() + "\"");
			System.out.println("victim: \"" + trigger.getVictim() + "\"");
		}
	}
}
